class CustomException(Exception):
    def __init__(self, message):
        self.message = message
        super().__init__(self.message)


def test_function():
    raise CustomException("This is a custom exception")


def cmd_test():
    help_str = """
1. 捕获异常 种类
2. 捕获异常 关键字
    """
    print(help_str)
    while True:
        cmd = input("请输入命令(1/2): ")

        if cmd == "1":
            try:
                test_function()
            except CustomException as e:
                print(f"1.捕获异常种类 CustomException: {e.message}")
        elif cmd == "2":
            try:
                test_function()
            except Exception as e:
                if "This is a custom exception" in str(e):
                    print(f"2.通过关键字捕获异常: {e}")
                else:
                    print(f"3.未匹配到异常关键字: {e}")


if __name__ == "__main__":
    cmd_test()
